package io.renren.modules.oa.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.oa.dao.OaPlanEmployeeDao;
import io.renren.modules.oa.entity.OaPlanEmployeeEntity;
import io.renren.modules.oa.service.OaPlanEmployeeService;
import io.renren.modules.sys.shiro.ShiroUtils;


@Service("oaPlanEmployeeService")
public class OaPlanEmployeeServiceImpl extends ServiceImpl<OaPlanEmployeeDao, OaPlanEmployeeEntity> implements OaPlanEmployeeService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
    	Long merchantId = ShiroUtils.getUserId();	//商户编号
        Page<OaPlanEmployeeEntity> page = this.selectPage(
                new Query<OaPlanEmployeeEntity>(params).getPage(),
                new EntityWrapper<OaPlanEmployeeEntity>().eq("merchant_id", merchantId)
                .orderBy("active", false).orderBy("sort", false)
        );

        return new PageUtils(page);
    }

	@Override
	public OaPlanEmployeeEntity selectByUserid(Long merchantId,String userid) {
		return this.selectOne(new EntityWrapper<OaPlanEmployeeEntity>().eq("merchant_id", merchantId).eq("userid", userid));
	}
	
	/**
	 * 查询值班人员列表
	 */
	@Override
	public List<OaPlanEmployeeEntity> queryActiveList(Long merchantId) {
		// TODO Auto-generated method stub
		return this.selectList(new EntityWrapper<OaPlanEmployeeEntity>()
				.eq("merchant_id", merchantId)
				.eq("active", 1)
				.orderBy("active", false).orderBy("sort", false));
	}
	
	@Override
	public List<OaPlanEmployeeEntity> queryAllList(Long merchantId) {
		// TODO Auto-generated method stub
		return this.selectList(new EntityWrapper<OaPlanEmployeeEntity>()
				.eq("merchant_id", merchantId)
				.orderBy("id", true));
	}

}
